﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour {
    GameObject asteroidPre;
    Transform startPos;    
    //陨石生成的间隔时间
     float intime = 1.5f;
    //计时器
     float timer;
	// Use this for initialization
	void Start () {
		//获取陨石预制体
        asteroidPre = Resources.Load<GameObject>("prop_asteroid_01");
        //获取开始的位置
        startPos = transform.Find("StartPos");
        timer = intime;

	}
	
	// Update is called once per frame
	void Update ()
    {      Timer();
        GetRandomAsteroid();
  
	}
    //计时器的方法
    void Timer()
    {
        timer += Time.deltaTime;

    }

    void GetRandomAsteroid()
    {
        if (timer >= intime)
        {
            float pos_x = Random.Range(-13.0f, 13.0f);
            Vector3 pos = new Vector3(pos_x, startPos.position.y, startPos.position.z);
            Instantiate(asteroidPre, pos, Quaternion.identity);
            timer = 0;
        }
    }
}
